package Java攻略._3_流式操作._6_字符串与流之间的转换;

public class _36_检查字符串是否属于回文 {

    public static void main(String[] args) {
        _36_检查字符串是否属于回文 _36 = new _36_检查字符串是否属于回文();
        String target = "1234321";
        boolean isTrue = _36.isPalindrome(target);
        System.out.println("是否为回文数：" + isTrue);
    }

    public boolean isPalindrome(String str){
        StringBuilder stringBuilder = new StringBuilder();
        for (char c : str.toCharArray()){
            if(Character.isLetterOrDigit(c)){
                stringBuilder.append(c);
            }
        }
        String zheng = stringBuilder.toString().toLowerCase();
        String fan = stringBuilder.reverse().toString().toLowerCase();
        return zheng.equals(fan);
    }
}
